package com.test.transaction;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.transaction.support.TransactionTemplate;

import com.test.mapper.NodeMapper;
import com.test.po.Node;

public class App {

	public static void main(String[] args) {
        // 用我们的配置文件来启动一个 ApplicationContext
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("com.test.transaction.demo");
        System.out.println("context 启动成功");

        TransactionTemplate transactionTemplate = context.getBean(TransactionTemplate.class);
        transactionTemplate.execute(status -> {
        	NodeMapper nodeMapper = context.getBean(NodeMapper.class);
            Node n1 = new Node();
            n1.setHostName("test5");
            n1.setPort("8005");
            int result = nodeMapper.save(n1);
            return result;
        });
        System.out.println("");
    }

}
